import { defineConfig, loadEnv } from 'vite'
import path from 'path'
import proxy from './proxy';
import h5Config from './vite.config.h5'
import pcConfig from './vite.config.pc'
import adminConfig from './vite.config.admin'
import merge from 'lodash/merge'

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {

  const env = loadEnv(mode, process.cwd());
  const platform = env.VITE_APP_PLARTFORM

  let padConfig = {}

  if (platform === 'pc') {
    padConfig = pcConfig
  } else if (platform === 'h5') {
    padConfig = h5Config
  } else if (platform === 'admin') {
    padConfig = adminConfig
  }

  const config = merge({
    resolve: {
      alias: [{
        find: '@admin',
        replacement: path.resolve(__dirname, "./src/admin")
      },
      {
        find: '@h5',
        replacement: path.resolve(__dirname, "./src/h5")
      },
      {
        find: '@pc',
        replacement: path.resolve(__dirname, "./src/pc")
      },
      {
        find: '~',
        replacement: path.resolve(__dirname, "./src")
      }],
    },
    server: {
      proxy
    }
  }, padConfig)

  return config
})
